package pe.com.ValoracionVivienda.security;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import org.apache.commons.codec.binary.Hex;

public class SHACryptographic {

	public static String criptografiar(String texto, String salt) throws NoSuchAlgorithmException{
		byte[] bytes;
		MessageDigest md = MessageDigest.getInstance("SHA-512");
		md.update(salt.getBytes());
		bytes = md.digest(texto.getBytes());
		
		return Hex.encodeHexString(bytes);
	}
	
	public static String getSalt() throws NoSuchAlgorithmException {
		SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
		byte[] salt = new byte[16];
		sr.nextBytes(salt);
		
		return salt.toString();
	}
}
